//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CShaderAdapter10.cpp>
///	@path	~/src/graphics/dx10/
///	@date	2008/12/29
///	@desc	.

#include "config/config.h"

#include "graphics/IGeometry.h"
#include "graphics/ITechnique.h"
#include "graphics/dx10/CShaderAdapter10.h"

namespace xeres {
	
	IMPL_IOBJECT_CLASS( CShaderAdapter10 );

	// CShaderAdapter10
	CShaderAdapter10::CShaderAdapter10( ID3D10InputLayout * layout , RefWeak<IShader> shader )
		: m_layout( layout )
		, m_shader( shader )
	{
	}
	// ~CShaderAdapter10
	CShaderAdapter10::~CShaderAdapter10( void )
	{
		if( m_layout )
		{
			UINT rest = m_layout->Release();
			if( rest != 0 )
			{
				TRACE_ERROR( _S("CShaderAdapter10::DTOR: Invalid ID3D10Effect reference count.") );
				FATAL_ABORT( _S("Invalid ID3D10InputLayout reference count.") );
			}
		}
	}
	// AdaptShader
	RefWeak<IShader> CShaderAdapter10::AdaptShader( RenderContext& rc )
	{
		return m_shader;
	}
	// AssembleShader
	void CShaderAdapter10::AssembleShader( RenderContext& rc )
	{
		// Set input layout
		rc.GetDX10()->IASetInputLayout( m_layout );
	}
	// Draw
	void CShaderAdapter10::Draw( RenderContext& rc , RefWeak<IGeometry> geo )
	{
		// Set input layout
		rc.GetDX10()->IASetInputLayout( m_layout );
		m_shader->Draw( rc , geo );
	}

} // namespace xeres
